import 'dart:convert';

class Person {
  String? _name;
  int? _age;
  String? _email;
  List<ACar>? _car;

  Person({String? name, int? age, String? email, List<ACar>? car}) {
    if (name != null) {
      this._name = name;
    }
    if (age != null) {
      this._age = age;
    }
    if (email != null) {
      this._email = email;
    }
    if (car != null) {
      this._car = car;
    }
  }

  String? get name => _name;

  set name(String? name) => _name = name;

  int? get age => _age;

  set age(int? age) => _age = age;

  String? get email => _email;

  set email(String? email) => _email = email;

  List<ACar>? get car => _car;

  set car(List<ACar>? car) => _car = car;

  Person.fromJson(Map<String, dynamic> json) {
    _name = json['name'];
    _age = json['age'];
    _email = json['email'];
    _car = json['car']?.cast<ACar>();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this._name;
    data['age'] = this._age;
    data['email'] = this._email;
    data['car'] = this._car;
    return data;
  }

  @override
  String toString() {
    var str = jsonEncode(this);
    return str;
  }
}

class ACar {
  String? _name;
  int? _price;

  ACar({String? name, int? price}) {
    if (name != null) {
      this._name = name;
    }
    if (price != null) {
      this._price = price;
    }
  }

  String? get name => _name;

  set name(String? name) => _name = name;

  int? get price => _price;

  set price(int? price) => _price = price;

  ACar.fromJson(Map<String, dynamic> json) {
    _name = json['name'];
    _price = json['price'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this._name;
    data['price'] = this._price;
    return data;
  }

  @override
  String toString() {
    var str = jsonEncode(this);
    return str;
  }
}
